<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org" xmlns:shiro="shiro.apache.org/tags">
<head>
    <th:block th:include="common/common_head :: commonHeader('环保承诺书')"/>
    <link rel="stylesheet" th:href="@{/static/js/plugins/jquery-layout/jquery.layout-latest.css}">
    <!-- <style type="text/css">.table {table-layout:fixed;}</style> -->
</head>
<body class="gray-bg">
<div class="container-div ui-layout-center">
    <div class="row">
        <div class="col-sm-12 search-condition">
            <form id="commimentForm" th:action="@{/environCommitment/list}" class="form-inline">
                <div class="select-list">
                    <ul>
                        <li class="col-sm-3">
                            <label>类型：</label>
                            <select name="type" sysDict="HBCNSLX" emptyFirst="true"></select>
                        </li>

                        <li class="col-sm-3">
                            <label>录入时间(起):</label>
                            <input type="text" name="startDate" id="startDate" autocomplete="off"/>
                        </li>

                        <li class="col-sm-3">
                            <label>录入时间(止):</label>
                            <input type="text" name="endDate" id="endDate" autocomplete="off"/>
                        </li>

                        <li class="col-sm-3">
                            <label>有效状态：</label>
                            <select id="validStatus" name="validStatus">
                                <option></option>
                                <option value="1">有效</option>
                                <option value="-1">无效</option>
                            </select>
                        </li>

                        <li class="col-sm-3">
                            <label>审核状态：</label>
                            <select id="reviewStatus" name="reviewStatus">
                                <option></option>
                                <option value="1">已审核</option>
                                <option value="-1">未审核</option>
                            </select>
                        </li>

                        <li class="col-sm-3">
                            <button id="commimentSearchBtn" type="button" class="btn btn-primary btn-rounded btn-sm"><i
                                    class="fa fa-search"></i>&nbsp;搜索
                            </button>
                            <button class="btn btn-warning btn-rounded btn-sm" type="reset"><i class="fa fa-eraser"></i>&nbsp;重置
                            </button>

                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-info order-table">
            <div class="btn-group hidden-xs toolbar" id="commimentToolBar" role="group">
                <a class="btn btn-outline btn-success btn-rounded" onclick="addCommitment()"
                   shiro:hasPermission="commitment:add">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-outline btn-success btn-rounded" onclick="lapse()">
                    <i class="fa fa-edit"></i> 失效
                </a>
            </div>
            <table id="commiment" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>

<!-- 模态框（Modal） -->
<div id="myCommitmentModal" style="display: none">
    <table class="layui-table" style="width:90%;margin: 0 auto">
        <thead style="height: 80px">
        <tr>
            <th colspan="4" style="font-size: 28px;text-align: center;line-height: 40px">环保承诺书明细</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td width="14%">供应商代码：</td>
            <td width="36%" id="vendorCode"></td>
            <td width="14%">供应商名称：</td>
            <td width="36%" id="vendorName"></td>
        </tr>
        <tr>
            <td>保证书编码：</td>
            <td id="guaranteeCode"></td>
            <td>合同签订日期：</td>
            <td id="contractDate"></td>
        </tr>
        <tr>
            <td>类别：</td>
            <td id="type"></td>
            <td>附件（环保承诺书，加盖公章）：</td>
            <td id="attach"></td>
        </tr>
        <tr>
            <td>录入人：</td>
            <td id="editor"></td>
            <td>录入时间：</td>
            <td id="editDate"></td>
        </tr>
        <tr>
            <td>审核人:</td>
            <td id="reviewer"></td>
            <td>审核时间:</td>
            <td id="reviewDate"></td>
        </tr>
        <tr>
            <td>审核结论：</td>
            <td id="conclusion"></td>
            <td>审核意见：</td>
            <td id="reviewComment"></td>
        </tr>
        <tr>
            <td>备注：</td>
            <td colspan="3" id="remark"></td>
        </tr>
        <tr>
            <td>注意事项：</td>
            <td style="color: red" colspan="3">
                1.环保承诺书：指厚声合作伙伴与厚声签订的合约书，注意要盖章备案的生效版
                <br> 2.环保承诺书版本：需合作伙伴签订最新版本，最新版本请在平台“管理表单”上下载
                <br>3.系统提交及审核权限：提交人-合作伙伴质量经理；审核人-厚声SQE马东，联系邮箱：sqe@uniohm.com.电话：0512-57631411-8832
            </td>
        </tr>
        </tbody>
    </table>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal" onclick="closeDialog()">关闭</button>
    </div>
</div>



<!--shiro不能在js中动态生成-->
<div id="permissionDiv" style="display: none;">
    <a class="btn btn-outline btn-success btn-rounded" shiro:hasPermission="commitment:audit">审核</a>
</div>

<!--引入公共js-->
<div th:include="common/onload_js :: onloadJS"></div>
<script type="text/javascript" th:src="@{/static/js/plugins/jquery-layout/jquery.layout-latest.js}"></script>

<script type="text/javascript">

    $(function () {
        // 初始化时间插件
        laydate.render({elem: '#startDate'});
        laydate.render({elem: '#endDate'});
        //初始化所有字典数据
        initDictDataSel();
    });

    var searcherBS = Searcher.createBS('#commiment',
        [
            {checkbox: true},
            {title: '保证书编号', field: 'guaranteeCode'},
            {title: '合同签订日期 ', field: 'contractDate'},
            {title: '类别', field: 'type'},
            {title: '录入人', field: 'editor'},
            {title: '录入时间', field: 'editDate'},
            {
                title: '录入状态', field: 'editStatus',
                formatter: function (value, row, index) {
                    if (value == 1) {
                        return "已提交";
                    } else if (value == 2) {
                        return "退回";
                    } else if (value == 3) {
                        return "待更新";
                    }
                }
            },
            {title: '审核人', field: 'reviewer'},
            {title: '审核时间', field: 'reviewDate'},
            {
                title: '审核结论', field: 'conclusion',
                formatter: function (value, row, index) {
                    if (value == 1) {
                        return "通过";
                    } else if (value == -1) {
                        return "退回";
                    }
                }
            },
            {
                title: '有效状态', field: 'validStatus',
                formatter: function (value, row, index) {
                    //审核被退回无效
                    if (value == -1) {
                        return "无效";
                    } else if (value == 1) {
                        return "有效";
                    }
                }
            },
            {
                title: "操作", field: '',
                formatter: function (value, row, index) {
                    value = '<button class="btn btn-outline btn-success btn-rounded"  onclick="fun(' + index + ')">查看</button>';
                    if (row.reviewer == undefined || row.reviewer == null || row.reviewer == '') {
                        $("#permissionDiv").find('a').each(function () {
                            $(this).attr("onclick", "audit('" + row.pkId + "')");
                            value += this.outerHTML;
                        })
                    }
                    return value;
                }
            }
        ]
    );

    /**
     * 查询数据
     */
    function refresh() {
        searcherBS.refresh();
    }

    /**
     * 关闭模态框
     */
    function closeDialog() {
        layer.closeAll();
    }

    /**
     * 跳转至新增页
     */
    function addCommitment() {
        var index = Dialog.openUrl("新增", ctxPath + '/environCommitment/addCommitment', {
            area: ['900px', '700px'],
            maxmin: true,
            end: function () {
            }
        });
        layer.full(index);
    }

    /**
     * 审核
     */
    function audit(id) {
        var index = Dialog.openUrl("审核", ctxPath + '/environCommitment/audit/' + id, {
            area: ['900px', '700px'],
            maxmin: true,
            end: function () {
            }
        });
        layer.full(index);
    }

    /**
     * 查看详情
     */
    function fun(index) {
        var rowData = $("#commiment").bootstrapTable("getData")[index];
        $("#vendorCode").text(rowData.vendorCode);
        $("#vendorName").text(rowData.vendorName);
        $("#guaranteeCode").text(rowData.guaranteeCode);
        $("#contractDate").text(rowData.contractDate);
        $("#type").text(rowData.type);
        var fileDir = rowData.attach;
        var suffix = fileDir.substr(fileDir.lastIndexOf("."));
        var prefix = fileDir.substring(0, fileDir.indexOf("_")).trim();
        prefix = prefix.substr(fileDir.lastIndexOf("/") + 1);
        var attach = prefix + suffix;
        $("#attach").empty().append('<a href="#" onclick="dowloadFileById(\'' + rowData.pkId + '\')"  style="color: blue">' + attach + '</a>');
        $("#editor").text(rowData.editor);
        $("#editDate").text(rowData.editDate);
        $("#editStatus").text(rowData.editStatus);
        $("#reviewer").text(rowData.reviewer);
        $("#reviewDate").text(rowData.reviewDate);
        $("#reviewComment").text(rowData.reviewComment);
        var con = rowData.conclusion;
        if (con == 1) {
            $("#conclusion").text('通过')
        } else if (con == -1) {
            $("#conclusion").text('退回')
        } else if (con == 0) {
            $("#conclusion").text('')
        }
        $("#remark").text(rowData.remark);
        Dialog.open("详情", $("#myCommitmentModal"), {area: ['1000px', '620px']});
    }

    /**
     **根据id下载报告文件
     **
     **/
    function dowloadFileById(id) {
        window.location.href = ctxPath + "/environCommitment/downloadFileById?id=" + id;
    }

    /**
     **失效
     **
     **/
    function lapse() {
        var validStatus = searcherBS.getSelectedRows("validStatus");
        if (validStatus.length != 1) {
            Dialog.errorMsg("请选择一行确认！");
            return;
        }

        if (validStatus == -1) {
            Dialog.errorMsg("该状态已经是无效状态");
            return;
        }
        var pkId = searcherBS.getSelectedRows("pkId");
        $.ajax({
            url: ctxPath + '/environCommitment/lapse',
            type: 'POST',
            dataType: "json",
            data: {"pkIds": pkId},
            cache: false, // 不缓存
            success: function (data) {
                layer.closeAll();
                if (data.code == 500) {
                    Dialog.errorMsg("修改失败！");
                } else {
                    Dialog.msg("操作成功!");
                }
                searcherBS.refresh();
            },
            error: function (data) {
                layer.closeAll();
                Dialog.errorMsg("修改失败！");
            }
        });

    }

</script>

</body>
</html>